#include "widget.h"
#include "./ui_widget.h"

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}


void Widget::on_btnClearText_clicked()
{
    ui->plainTextEdit->clear();
}


void Widget::on_btnInitItems_clicked()
{
    QIcon icon;
    icon.addFile(":/icons/images/city.png");

    ui->comboItems->clear();
    for (int i = 0; i < 20; ++i) {
        ui->comboItems->addItem(icon, QString("Item%1").arg(i));
    }
//    ui->comboItems->addItems(QStringList);
}


void Widget::on_chkEditable_clicked(bool checked)
{
    ui->comboItems->setEditable(checked);
}


void Widget::on_btnClearItems_clicked()
{
    ui->comboItems->clear();
}


void Widget::on_btnInitCities_clicked()
{
    ui->comboCities->clear();
    QMap<QString, int> city_zone;

    city_zone.insert("北京", 10);
    city_zone.insert("沙河", 20);
    city_zone.insert("上海", 50);
    city_zone.insert("南昌", 90);

    foreach(const QString& str, city_zone.keys()) {
        ui->comboCities->addItem(str, city_zone.value(str));
    }
}


void Widget::on_comboItems_currentTextChanged(const QString &arg1)
{
    ui->plainTextEdit->appendPlainText(arg1);
}


void Widget::on_comboCities_currentIndexChanged(int index)
{
    Q_UNUSED(index); // To avoid compiling warning

    QString str = ui->comboCities->currentText() + " "
                  + ui->comboCities->currentData().toString();
    ui->plainTextEdit->appendPlainText(str);
}

